package com.example.gametestproject;
import java.util.Vector;

import com.example.gametestproject.IAnimationData;
public class AnimationData implements IAnimationData
{
	private Vector<Integer> mFrames;
	private int mCurFrmIdx;
	private boolean mIsRunning;
	//may be we need to control frame rate of animation
	//private float mAnimDuration;// seconds
	//private long mLasteUpdateTime = 0;
	private boolean mIsRepeat = false;
	
	public AnimationData()
	{
		this.mFrames = null;
		this.mCurFrmIdx = 0;
		this.mIsRunning = true;
	}
	
	public AnimationData(int bitmapIdx)
	{
		this.mFrames = new Vector<Integer>();
		this.mFrames.add(bitmapIdx);
		this.mCurFrmIdx = 0;
		this.mIsRunning = false;
	}

	public AnimationData (Vector<Integer> frame, int curFrm, boolean isRepeat, boolean isStart, float animDru)
	{
		this.mFrames = frame;
		this.mCurFrmIdx = curFrm;
		this.mIsRunning = isStart;
		this.mIsRepeat = isRepeat;
		//this.mAnimDuration = animDru;
	}
	public void setAminationFrames(Vector<Integer> frame)
	{
		this.mFrames = frame;
		this.mCurFrmIdx = 0;
		this.mIsRunning = true;
		this.mIsRepeat = false;
	}
	
	public Vector<Integer> getAnimationFrames()
	{
		return this.mFrames;
	}
	
	@Override
	public int getCurrentFrameIndex()
	{
		if (mFrames != null && mFrames.size() > this.mCurFrmIdx)
		{
			return mFrames.get(this.mCurFrmIdx);
		}
		return -1;
	}

	@Override
	public int update()
	{

		if (this.mIsRunning)
		{
			if (this.mIsRepeat)
			{
				this.mCurFrmIdx = ++ this.mCurFrmIdx % this.mFrames.size();
			}
			else
			{
				if (this.mCurFrmIdx < this.mFrames.size() - 1)
				{
					++ this.mCurFrmIdx;
				}
			}
		}
		//Log.i("AnimationData", " " + this.mCurFrmIdx);
		return this.getCurrentFrameIndex();
	}
	
	@Override
	public boolean isStoped()
	{
		return mFrames == null || mFrames.isEmpty() || !this.mIsRunning ||
				(!mIsRepeat && this.mCurFrmIdx == this.mFrames.size());
	}
	
	@Override
	public void startAnimation()
	{
		this.mIsRunning = true;
		//this.mLasteUpdateTime = System.currentTimeMillis();
	}
	
	@Override
	public void stopAnimation()
	{
		this.mIsRunning = false;
	}
	
	@Override
	public void restart()
	{
		this.mCurFrmIdx = 0;
	}
}
